<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>WebSocket 客户端</title>
</head>
<body>
	<div>
		<input id="msg" type="text" value="" />
		<input type="submit" value="发送" onclick="sendMsg()" />
	</div>
	<div id="message"></div>
	<script type="text/javascript">
		var webSocket = new WebSocket('ws://localhost:8080/game/websocket');
		
		function getMessage(){
			return document.getElementById("message").innerHTML;
		}
		
		webSocket.onerror = function(event){
			document.getElementById("message").innerHTML = getMessage() + "error: " + event.data + "<br>";
		}
		
		webSocket.onopen = function(event){
			document.getElementById("message").innerHTML = getMessage() + "连接服务器成功<br>";
		}
		
		webSocket.onmessage = function(event){
			document.getElementById("message").innerHTML = getMessage() + "来自客户端的消息：" + event.data + "<br>";
		}
		
		webSocket.onclose = function(event){
			document.getElementById("message").innerHTML = getMessage() + "连接服务器中断<br>";
		}
		
		function sendMsg(){
			var msg = document.getElementById("msg").value;
			webSocket.send(msg);
		}
	</script>
</body>
</html>